package com.study.mongodbdynamicdatasource.listener;

import com.study.mongodbdynamicdatasource.config.MongoDbContext;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;

/**
 * @Name: MongoDSRequestListener
 * @Description: java类作用描述
 * @Author: yn
 * @CreateDate: 2023/7/14 15:36
 * @Remark: 特殊说明
 * @Version: 1.0
 */
@WebListener
public class MongoDSRequestListener implements ServletRequestListener {
	/**
	 * The request is about to come into scope of the web application.
	 * The default implementation is a NO-OP.
	 *
	 * @param sre Information about the request
	 */
	@Override
	public void requestInitialized(ServletRequestEvent sre) {
		ServletRequestListener.super.requestInitialized(sre);
	}

	/**
	 * The request is about to go out of scope of the web application.
	 * The default implementation is a NO-OP.
	 *
	 * @param sre Information about the request
	 */
	@Override
	public void requestDestroyed(ServletRequestEvent sre) {
		ServletRequestListener.super.requestDestroyed(sre);
		MongoDbContext.clearMongoDbFactory();
	}
}
